home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #11
/
Amiga Plus CD - 2002 - No. 11.iso
/
Tools
/
Freeware
/
DiskMaster
/
Rexx
/
DMMultiRename.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
2002-10-27
|
3KB
|
123 lines
/* $VER: DMMultiRename.rexx 1.1 (2.10.98) by J.Tierney
DiskMaster II Multi-Rename v1.1
10/2/98 by J. Tierney <jtierney@cyberlink-inc.com>
Began: 2/8/98
Function: Rename all selected files in a similar manner, possibly
stripping file extensions and adding index numbers.
A requester will ask for a pattern, which may be:
Patterns: * - Old name.
-. - Strip extension. May be used more than once. No effect if
an extension isn't found. Use with "*".
+n - Index. <n> = starting number. Each "+" will be one digit.
Ex: +5 = "5", "6", "7", ...
++2 = "02", "03", "04", ...
+++ = "000", "001", "002", ...
All other text will become part of the new file name.
Usage: AddCmd MultiRename, 10, REXX REXX:DMMultiRename.rexx
Examples:
Selected files = "Whipple.guide.xpk", "Bla.txt", "Fruit.jpg"
Pattern: *-.
Result: "Whipple.guide", "Bla", "Fruit"
Same name, strip one extension.
Pattern: *-.-.-.
Result: "Whipple", "Bla", "Fruit"
Same name, strip three extensions.
Pattern: *.bak
Result: "Whipple.guide.xpk.bak", "Bla.txt.bak", "Fruit.jpg.bak"
Same name, append ".bak".
Pattern: File+++5L
Result: "File005L", "File006L", "File007L"
Rename all the files to "File###L", where "###" is a 3 number
index beginning at 5.
Pattern: *-.-.-..fake
Result: "Whipple.fake", "Bla.fake", "Fruit.fake"
Same name, strip three extensions, append ".fake".
*/
OPTIONS RESULTS
'CONFIRM "Enter new name:" Okay Cancel *-.-.++1'
pat = result
DIRLIST VAR dlist SEL
STATUS P
path = result
IF RIGHT(path, 1) ~= ':' THEN path = path || '/'
idx.places = ''
DO i = 1 TO dlist.name.0
newname = MakeNewName(pat, dlist.name.i)
'RENAME' path || dlist.name.i path || newname
END
'DESELECT *'
EXIT 0
MakeNewName: PROCEDURE EXPOSE idx.
PARSE ARG pat, oldname
/* Index? */
s = POS('+', pat)
IF s > 0 THEN DO
IF idx.places = '' THEN DO
DO x = 1 UNTIL SUBSTR(pat, s + x, 1) ~= '+'
END
idx.places = x
DO n = 0 UNTIL ~DATATYPE(SUBSTR(pat, s + x + n, 1), 'N')
END
idx.extra = n
IF n > 0 THEN DO
str = SUBSTR(pat, s + x, n)
idx.num = str - 1
END
ELSE DO
idx.num = -1
END
END
pat = DELSTR(pat, s, idx.places + idx.extra)
idx.num = idx.num + 1
pat = INSERT(RIGHT(idx.num, idx.places, '0'), pat, s - 1)
END
/* Strip extension? */
DO UNTIL s = 0
s = POS('-.', pat)
IF s > 0 THEN DO
x = LASTPOS('.', oldname)
IF x > 0 THEN oldname = LEFT(oldname, x - 1)
pat = DELSTR(pat, s, 2)
END
END
/* Sandwich the old name between the new bits? */
s = POS('*', pat)
IF s > 0 THEN DO
pat = DELSTR(pat, s, 1)
pat = INSERT(oldname, pat, s - 1)
END
RETURN pat